home *** CD-ROM | disk | FTP | other *** search
- Path: gramercy.ios.com!lalit
- From: lalit@gramercy.ios.com (lalit gidwani)
- Newsgroups: comp.lang.c++
- Subject: Re: Exceptions vs. assertions
- Date: 5 Jan 1996 02:00:55 GMT
- Organization: Internet Online Services
- Message-ID: <4ci0on$77p@news2.ios.com>
- References: <4cbfac$kst@dawn.mmm.com> <DKMJsE.LH5@falcon.daytonoh.attgis.com>
- NNTP-Posting-Host: gramercy.ios.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Dick Menninger (Dick.Menninger@DaytonOH.ATTGIS.COM) wrote:
-
- : > ==========Kevin J Hopps, 1/2/96==========
- :
- : > Chris Page (page@tiac.net) wrote:
- : > > lalit@gramercy.ios.com (lalit gidwani) wrote:
-
- : [stuff deleted]
-
- : > > is this: If I expect a condition to occur during normal operation of
- : > > my program, then I do not use exceptions for it. I use exceptions,
- : > > only for exceptionally conditions, which I do not expect to
- : occur, but
- : > > I have to anticipate.
- : >
- : > This is a good approach. The issue of whether to throw exceptions or
- : > return status values is best decided by how likely the failure is than
- : > by how catastrophic it is. (Besides, the caller of a function knows
- : > better than the function itself how costly the failure is.)
-
- : Exceptions are a control paradigm. Would you choose any
- : other control paradigm based on frequency or importance
- : of the issue being modeled (programmed)? It would seem that
- : the choice should be based on trying for the best expression
- : of the problem. I suspect there are problems to be modeled
- : where they are best expressed with an exception used for
- : the success path. In fact, that is one of the reasons I push
- : for multiple simultaneous exceptions being valid in the language
- : (so you can have an error exception while returning a success
- : exception). Such problems are likely to be related to problems
- : where multi-level breaks (usually simulated by a goto) are very
- : helpful in clarifying the expression of the model. For such
- : problems, the solution may perform better with an exception
- : for success.
-
- : Good Day
- : Dick
- : Dick.Menninger@DaytonOH.ATTGIS.COM
-
-
- Thanks Dick!
-
- I have a few simple lines of code. Do you think
- the C++ exception mechanism has been properly used here:
-
- class SaveError; // exception class
-
- void GetDataFromScreen() throw();
- void SaveDataInDatabase() throw( SaveError );
- void SaveCurrentInvoice() throw( SaveError );
-
-
- int main( int argc, char **argv )
- {
- /*****************
-
- Send the selected invoice to screen and
- wait for user to say he wants to
- save the current invoice.
-
- ******************/
-
- try
- {
- SaveCurrentIncoice();
- }
- catch( SaveError se )
- {
- // send error message to the user
- }
-
- }// main
-
- void SaveCurrentInvoice() throw ( SaveError )
- {
- GetDataFromScreen() // always succeeds in this system
- try
- {
- SaveDataToDatabase();
- }
- catch( SaveError err )
- {
- throw err;
- }
- }
-
-
- If this code seems OK, I have two comments:
-
- 1. It seems to increase the amount of code. However, it seems
- that the exception-handling would reduce code if there
- where many lines of code in a try block that could throw
- exceptions.
- 2. This seems to be an issue that needs to be thought out well.
-
- P.S. The syntax may not be absolutely correct.
-
-
- Thanx
- LG
-